home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / index.arc / IDXTEST4.BAS < prev    next >
Encoding:
BASIC Source File  |  1987-01-24  |  4.4 KB  |  183 lines

  1. rem $title:'Indexing routines & test program.'
  2. rem $subtitle:'Test / Calling program'
  3. rem $include:'aecommon.bas'
  4.  
  5. def fntdiff%(a$,b$)
  6.     k%=val(mid$(a$,4,2))*60+val(mid$(a$,7,2))
  7.     k%=k%-(val(mid$(b$,4,2))*60+val(mid$(b$,7,2)))
  8.     fntdiff%=abs(k%)
  9. end def
  10.  
  11.     print
  12.     print "Driver to test the btree routines."
  13.     print "(c) Roy Barrow, 1987. version 2.08."
  14.     print
  15. menu:
  16.     fl%=1%
  17.     print "     1....create"
  18.     print "     2....open"
  19.     print "     3....close"
  20.     print "     4....insert"
  21.     print "     5....delete"
  22.     print "     6....next in sequence"
  23.     print "     7....find"
  24.     print "     9....previous in sequence"
  25.     print "     10...list in forward sequence"
  26.     print "     11...mass input of keys"
  27.     print "     12...automated mass input from file words.dat"
  28.     print
  29.     print "Index:";ixn$;" Next=";xh%(fl%,3);"Next Del=";xh%(fl%,4);"No Keys=";xh%(fl%,2)
  30.  
  31.     input op$
  32.     op%=val(op$)
  33.     if op%=0 then goto fini
  34.     if op%<1 or op%>12 then goto menu
  35.     on op% goto create,opfile,clfile,infile,delfile,nxsseq,nfind,dump,prev,fseq,massin,aumass
  36.     goto menu
  37.  
  38. create:
  39.     call bit.creat
  40.     goto menu
  41.  
  42. opfile:
  43.     print "opening index"
  44.     line input "enter index name: ",ixn$
  45.         if ixn$="" then print "no index name / open index !":goto menu
  46.     call bit.open(fl%,ixn$)
  47.         if aesb.fatal% then
  48.             print "error opening index."
  49.             end
  50.         end if
  51.     print "keylength  =";xh%(fl%,1)
  52.     print "next avail =";xh%(fl%,3)
  53.     goto menu
  54.  
  55. infile:
  56.         if ixn$="" then print "no index name / open index !":goto menu
  57.     input "enter key to insert: ",kin$
  58.     input "enter num for master record: ",acc%
  59.     call bit.ins(fl%,kin$,acc%,what%)
  60.     if what%=1 then print "succeeded" else print "failed"
  61.     goto menu
  62.  
  63. delfile:
  64.         if ixn$="" then print "no index name / open index !":goto menu
  65.     input "enter key to delete: ",kin$
  66.     call bit.find(fl%,kin$,acc%,what%)
  67.     if acc%=0 then print "not there.":goto menu
  68.     if acc%<0 then print "closest match:";kin$:goto menu
  69.     print kin$;" found at record";acc%
  70.     call bit.kill(fl%,kin$,acc%,what%)
  71.     if what%=1 then print "succeeded" else print "failed"
  72.     goto menu
  73.  
  74. clfile:
  75.         if ixn$="" then print "no index name / open index !":goto menu
  76.     call bit.close(fl%)
  77.         ixn$=""                                ' just to say none open!
  78.     goto menu
  79.  
  80. nfind:
  81.         if ixn$="" then print "no index name / open index !":goto menu
  82.     input "key to search for:",kin$
  83.     call bit.find(fl%,kin$,acc%,what%)
  84.     if acc%=0 then print "not there.":goto menu
  85.     if acc%<0 then print "closest match:";kin$:goto menu
  86.     print kin$;" found at record";acc%
  87.     goto menu
  88.  
  89. nxsseq:
  90.         if ixn$="" then print "no index name / open index !":goto menu
  91.     ktmp$=kin$
  92.     call bit.next(fl%,kin$,acc%,what%)
  93.     if acc%=0% and what%=0% then
  94.         print "No next record,";ktmp$;" probably the end (if legal)"
  95.         kin$=ktmp$
  96.         call bit.find(fl%,kin$,acc%,what%)
  97.     else
  98.         print kin$;" is result"
  99.     end if
  100. goto menu
  101.  
  102. fseq:
  103.         if ixn$="" then print "no index name / open index !":goto menu
  104.     call bit.left(fl%,kin$,acc%,what%)
  105.     print kin$;" ";
  106.     pacc%=0%
  107.     while acc%<>pacc%
  108.         pacc%=acc%
  109.         call bit.next(fl%,kin$,acc%,what%)
  110.         print kin$;" ";
  111.     wend
  112.     print
  113.     goto menu
  114.  
  115. dump:
  116.     goto menu
  117.  
  118. fini:
  119.         if ixn$="" then end
  120.     call bit.close(fl%)
  121.     end
  122.  
  123. prev:
  124.         if ixn$="" then print "no index name / open index !":goto menu
  125.     ktmp$=kin$
  126.     call bit.prev(fl%,kin$,acc%,what%)
  127.     if acc%=0% and what%=0% then
  128.         print "No previous record,";ktmp$;" probably the end (if legal)"
  129.         kin$=ktmp$
  130.         call bit.find(fl%,kin$,acc%,what%)
  131.     else
  132.         print kin$;" is result"
  133.     end if
  134.     goto menu
  135.  
  136.  
  137. massin:
  138.         if ixn$="" then print "no index name / open index !":goto menu
  139.     input "start record: ";acc%
  140. nmass:
  141.     input "enter key to insert: ",kin$
  142.     if kin$="" then goto menu
  143.     call bit.ins(fl%,kin$,acc%,what%)
  144.     if what%=1 then print "succeeded" else print "failed"
  145.     acc%=acc%+1
  146.     goto nmass
  147.  
  148. aumass:
  149.     cls
  150.         if ixn$="" then print "no index name / open index !":goto menu
  151.     open "words.dat" for input as #5
  152.     acc%=1
  153.     pl%=10
  154.     ph%=0
  155. tmass:
  156.     what%=1%
  157.     while not eof(5) and what%=1%
  158.         line input #5,ky$
  159.         print ky$;acc%
  160.         kin$=ky$
  161.         if kin$="" then goto null
  162.         e$=time$
  163.         call bit.ins(fl%,kin$,acc%,what%)
  164.         f$=time$
  165.         th%=fntdiff%(e$,f$)
  166.         av!=av!+th%
  167.         if th%<pl% then pl%=th%
  168.         if th%>ph% then ph%=th%
  169.         if what%=1 then
  170.             kp$=ky$+str$(xh%(fl%,3))+" "+str$(av!/acc%)
  171.             if len(kp$)<70% then
  172.                 kp$=kp$+string$(70%-len(kp$),32%)
  173.      '        call qprint(kp$,6%,1%)
  174.             end if
  175.         acc%=acc%+1
  176.         end if
  177. null:
  178.     wend
  179.     close 5
  180.     goto menu
  181.  
  182.  
  183.